home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 9.8 KB | 285 lines | [TEXT/MPS ] |
- // UBehavior.h
- // Copyright © 1991-96 by Apple Computer, Inc. All rights reserved.
-
-
- #ifndef __UBEHAVIOR__
- #define __UBEHAVIOR__
-
- // MacApp
-
- #ifndef __UGEOMETRY__
- #include "UGeometry.h"
- #endif
-
- #ifndef __UOBJECT__
- #include "UObject.h"
- #endif
-
- // just for IdlePhase
- #ifndef __UEVENTHANDLER__
- #include "UEventHandler.h"
- #endif
-
- class MScriptableObject;
- class TAppleEvent;
- class TDocument;
- class TEventHandler;
-
- //----------------------------------------------------------------------------------------
- // TBehavior
- //----------------------------------------------------------------------------------------
-
- class TBehavior : public TObject
- {
- MA_DECLARE_CLASS;
-
- public:
- TBehavior();
- // Constructor
-
- //------------------------------------------------------------------------------------
- // Initializer and I<Method>.
- //------------------------------------------------------------------------------------
-
- void IBehavior(IDType itsIdentifier);
- // Initialization method
-
- virtual TObject* Clone(); // OVERRIDE
- // We have overridden this to do a deep clone of the behavior
-
- virtual ~TBehavior();
- // Pass the Free message on to all behaviors in the chain before calling
- // Inherited::Free
-
- //------------------------------------------------------------------------------------
- // Idling.
- //------------------------------------------------------------------------------------
-
- virtual void SetIdleFreq(long newIdleFreq);
- // Call to set the handler's idling frequency.
-
- virtual long NextIdle();
- // Returns the number Tickcount for when the handler should next be idled.
-
- virtual void HandleIdle(IdlePhase phase);
- // Calls DoIdle if the handler is eligible.
-
- virtual Boolean DoIdle(IdlePhase phase);
- // Returns true if it frees itself so caller can know
-
- //------------------------------------------------------------------------------------
- // Stream I/O protocol support.
- //------------------------------------------------------------------------------------
-
- virtual void ReadFrom(TStream* aStream);
-
- virtual void WriteTo(TStream* aStream);
-
-
- //------------------------------------------------------------------------------------
- // Chain Management Methods
- //------------------------------------------------------------------------------------
-
- inline void SetNextBehavior(TBehavior* nextBehavior)
- { fNextBehavior = nextBehavior; }
- // Set the fNextBehavior field
-
- inline void SetPreviousBehavior(TBehavior* previousBehavior)
- { fPreviousBehavior = previousBehavior; }
- // Set the fPreviousBehavior field
-
- inline TBehavior* GetNextBehavior() const
- { return fNextBehavior; }
- // Return the next behavior
-
- TBehavior* GetNextEnabledBehavior() const;
- // Return the next enabled behavior
-
- virtual void SetOwner(TEventHandler* itsOwner);
- // Set the fOwner field
-
- Boolean IsOwnerSelected() const
- { return fIsOwnerSelected; }
- // Returns the current state of the 'fIsOwnerSelected' flag
-
- virtual void SelectOwner (Boolean select);
- // Called when this behavior's owner is selected. Sets the fIsOwnerSelected flag
-
- inline Boolean IsEnabled() const
- { return fEnabled; }
- // Returns the current state of the 'fEnabled' flag
-
- virtual void SetEnabled(Boolean enabled);
- // Sets the 'fEnabled' flag.
-
- void InsertBefore(TBehavior* insertMe,
- TBehavior* before);
- // Insert behavior 'insertMe' ahead of behavior 'before' in the chain
-
- void InsertAfter(TBehavior* insertMe,
- TBehavior* after);
- // Insert behavior 'insertMe' after of behavior 'after' in the chain
-
- void AppendBehavior(TBehavior* aBehavior);
- // Add 'aBehavior' to the end of the list
-
- void RemoveBehavior(TBehavior* removeMe);
- // Remove behavior 'removeMe' from the chain
-
- //------------------------------------------------------------------------------------
- // • Event Filtering Methods
- //------------------------------------------------------------------------------------
-
- virtual void DoCommandKeyEvent(TToolboxEvent* event);
- // Allows behaviors to respond to CommandKey events, if there is a next behavior
- // it passes the message on down the chain otherwise it calls the corresponding
- // method of its Owner
-
- virtual void DoEvent(EventNumber eventNumber,
- TEventHandler* source,
- TEvent* event);
- // Allows behaviors to handle events, if there is a next behavior it passes the
- // message on down the chain otherwise it calls the corresponding method of its
- // Owner
-
- virtual void DoKeyEvent(TToolboxEvent* event);
- // Allows behaviors to respond to KeyCommands, if there is a next behavior it
- // passes the message on down the chain otherwise it calls the corresponding
- // method of its Owner
-
- virtual void DoKeyUp(TToolboxEvent* event);
- // Allows behaviors to respond to KeyUps, if there is a next behavior it passes
- // the message on down the chain otherwise it calls the corresponding method of
- // its Owner
-
- virtual void DoMenuCommand(CommandNumber aCommandNumber);
- // Allows behaviors to handle menu events, if there is a next behavior passes the
- // message on down the chain otherwise it calls the corresponding method of its
- // Owner
-
- virtual Boolean DoScriptCommand(CommandNumber aCommandNumber,
- TAppleEvent* message,
- TAppleEvent* reply);
- // Allows behaviors to handle appleevents. Returns true if the event is handled,
- // and false if it was not.
-
- virtual void DoSetupMenus();
- // Allows behaviors to handle menu setup if there is a next behavior passes the
- // message on down the chain otherwise it calls the corresponding method of its
- // Owner
-
- virtual void DoBehaviorUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace);
- // Allows behaviors to handle updates from notifiers
-
- // • Special hooks which are used when attached to a TView
-
- virtual Boolean DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* event,
- CPoint hysteresis);
- // Allow view behaviors to intercept mouse commands, if there is a next behavior
- // it passes the message on down the chain otherwise by default returns false
-
- virtual Boolean DoMouseUp(VPoint& theMouse,
- TToolboxEvent* event,
- CPoint hysteresis);
- // Allow view behaviors to intercept mouse up commands.
-
- virtual void Draw ( const VRect& area );
- // Called during a views drawing process, after the view has been called to draw
- // itself and before the views subviews are called to draw themselves. The 'area'
- // in need of drawing is passed in.
-
- virtual Boolean DoSetCursor(const VPoint& localPoint, RgnHandle cursorRegion);
- // Gives the view behavior the opportunity to setup the cursor, if there is a nex
- // behavior it passes the message on down the chain otherwise by default returns
- // false
-
- // • Special hooks which are used when attached to a TApplication
-
- virtual Boolean DoToolboxEvent(TToolboxEvent* event);
- // When this is called by MacApp, theEvent is the event to be processed.
-
- virtual void DoPostCreate(TDocument* itsDocument);
- // Gives the behavior the opportunity to do any processing after its
- // associated view has been fully created
-
- //------------------------------------------------------------------------------------
- // data members
- //------------------------------------------------------------------------------------
- public:
- TEventHandler* fOwner; // The event handler that owns this behavior
-
- TBehavior* fNextBehavior; // The next behavior in the chain
-
- TBehavior* fPreviousBehavior; // The previous behavior in the chain
-
- IDType fIdentifier;
-
- long fIdleFreq; // the minimum number of ticks that can pass
- // before my DoIdle is called. 0 = call as
- // often as possible. n..kMaxIdleTime = call
- // every fIdleFreq ticks.
-
- long fLastIdle; // the tick count the last time my DoIdle was
- // called.
-
- Boolean fEnabled; // True if this behavior is enabled. If false,
- // this behavior will be skipped over as
- // though it were not in the chain.
-
- Boolean fIsOwnerSelected; // True if this behavior's owner is "selected"
- // as in a prototyping environment. Treat this
- // instance variable as private, and call
- // TEventHandler::SetSelect
-
-
- };
-
-
- //----------------------------------------------------------------------------------------
- // CBehaviorIterator: A simple iterator for the behavior chain.
- //----------------------------------------------------------------------------------------
-
- class CBehaviorIterator
- {
- public:
- CBehaviorIterator(TEventHandler* itsEventHandler);
-
- inline Boolean More() // override
- { return (fCurrentBehavior != NULL); }
- // Returns true if there are more elements to iterate over
-
- inline void Reset() // override
- { fCurrentBehavior = fFirstBehavior; }
- // Resets the iterator to begin again
-
- inline TBehavior* CurrentBehavior()
- { return fCurrentBehavior; }
- // returns the current Behavior in the Behavior chain
-
- inline TBehavior* FirstBehavior()
- { Reset(); return fFirstBehavior; }
- // Resets the iterator to begin again and returns the first Behavior in the
- // Behavior chain
-
- inline TBehavior* NextBehavior()
- { Advance(); return fCurrentBehavior; }
- // returns the next Behavior in the Behavior chain
-
- protected:
- void Advance(); // override
- // Advances the iteration
-
- private:
- TBehavior* fFirstBehavior;
-
- TBehavior* fCurrentBehavior;
-
- TBehavior* fNextBehavior;
- };
-
- #endif
-